import O1HD from "../../../../engines/gameEngine";

const {ccclass, property} = cc._decorator;

enum FindSpriteObjState{
    NORMAL,
    CLICK
}

@ccclass
export default class levelFindSpriteClickObj extends cc.Component {

    @property({type:cc.Node,displayName:"正常状态下显示的图片"})
    normalSp:cc.Node = null;

    @property({type:cc.Node,displayName:"被点击之后显示的图片"})
    clickSp:cc.Node = null;

    @property({type:cc.Node,displayName:"非正常状态下需要显示的图片"})
    clickShowNode:cc.Node[] = [];

    nodeState:FindSpriteObjState = FindSpriteObjState.NORMAL;

    protected onLoad(): void {
        this.node.on('touchend',this.onTouchEnd,this);
        this.init();
    }

    onTouchEnd(e:cc.Event.EventTouch){
        if(this.nodeState == FindSpriteObjState.NORMAL){
            this.node.off('touchend',this.onTouchEnd,this);
            this.nodeState = FindSpriteObjState.CLICK;
            // O1HD.getManagers().soundMgr.playSound("mainSound/hcy1");
            O1HD.getManagers().soundMgr.playVibrate();
            this.onChangeState();
        }else{
            this.nodeState = FindSpriteObjState.NORMAL;
            this.onChangeState();
        }
    }

    onChangeState(){
        if(this.nodeState == FindSpriteObjState.CLICK){
            this.clickSp.active = true;
            this.normalSp.active = false;
            this.showClickObjs();
        }else{
            this.hideClickObjs();
            this.normalSp.active = true;
            this.clickSp.active = false;
        }
    }

    init(){
        this.onChangeState();
    }

    showClickObjs(){
        this.clickShowNode.forEach((n:cc.Node)=>{
            n.active = true;
        });
    }
    
    hideClickObjs(){
        this.clickShowNode.forEach((n:cc.Node)=>{
            n.active = false;
        });
    }

}
